package uestc.lj.gulishop.search.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import uestc.lj.gulishop.search.service.MallSearchService;
import uestc.lj.gulishop.search.vo.SearchParamVO;
import uestc.lj.gulishop.search.vo.SearchResponseVO;

import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {
    @Autowired
    private MallSearchService mallSearchService;

    @GetMapping("/list.html")
    public String listPage(SearchParamVO searchParamVO, Model model, HttpServletRequest request) {
        String queryString = request.getQueryString();
        searchParamVO.set_queryString(queryString);
        // 1.根据页面传入的检索条件查询要检索的商品
        SearchResponseVO result = mallSearchService.search(searchParamVO);
        // 2.添加到model中
        model.addAttribute("result", result);
        return "list";
    }
}
